<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增刀具监测')" />
</head>
<body>
    <form class="layui-form">
        <div class="mainBox">
            <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">刀具位置：</label>
                <div class="layui-input-block">
                    <input type="text" name="toolSpace" placeholder="请输入刀具位置" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">刀具图片：</label>
                <div class="layui-input-block">
                    <input type="text" name="toolPrc" placeholder="请输入刀具图片" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">刀具类型：</label>
                <div class="layui-input-block">
                    <select name="toolType"    dict-code="input" >
                        <option value="">所有</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">刀具对应的主轴：</label>
                <div class="layui-input-block">
                    <input type="text" name="toolAxis" placeholder="请输入刀具对应的主轴" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">刀具对应的电机：</label>
                <div class="layui-input-block">
                    <input type="text" name="toolMotor" placeholder="请输入刀具对应的电机" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">刀具状态：</label>
                <div class="layui-input-block">
                    <input type="text" name="toolState" placeholder="请输入刀具状态" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">购买厂家：</label>
                <div class="layui-input-block">
                    <input type="text" name="manufacturer" placeholder="请输入购买厂家" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">售后电话：</label>
                <div class="layui-input-block">
                    <input type="text" name="manufacturerPhone" placeholder="请输入售后电话" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">保修期：</label>
                <div class="layui-input-block">
                    <input type="text" name="warrantyPeriod" placeholder="请输入保修期" class="layui-input" />
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">使用时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input type="text" name="creatTime" class="layui-input" id="creatTime" >
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">null：</label>
                <div class="layui-input-block">
                    <input type="text" name="spare1" placeholder="请输入null" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">null：</label>
                <div class="layui-input-block">
                    <input type="text" name="spare2" placeholder="请输入null" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">null：</label>
                <div class="layui-input-block">
                    <input type="text" name="spare3" placeholder="请输入null" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">null：</label>
                <div class="layui-input-block">
                    <input type="text" name="spare4" placeholder="请输入null" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">null：</label>
                <div class="layui-input-block">
                    <input type="text" name="spare5" placeholder="请输入null" class="layui-input" />
                </div>
            </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="tool-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
</body>
<th:block th:include="include :: footer" />
<script th:inline="javascript">

    layui.use(['form', 'jquery','laydate','dictionary'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;

        let prefix = "/system/tool/"

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        laydate.render({
                            elem: '#creatTime'
                        });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
        form.on('submit(tool-save)', function (data) {
            for(var key in data.field){
                var type=$(data.form).find("input[name='"+key+"']").attr("type");
                if(type=="checkbox"){
                    var value="";
                    $(data.form).find("input[name='"+key+"']:checked").each(function(){
                        value+=$(this).val()+",";
                    })
                    if(value!=""){
                        value=value.substr(0,value.length-1);
                        data.field[key]=value;
                    }

                }
            }
            $.ajax({
                url: prefix+'save',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            parent.layui.table.reload("tool-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    });
</script>
</html>